package main

import (
	"edu-common/nacos/boot"
	"github.com/gogf/gf/contrib/registry/etcd/v2"
	"github.com/gogf/gf/contrib/rpc/grpcx/v2"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/gctx"
	"user-api/internal/cmd"
	"user-api/internal/logic"
)

func main() {
	boot.InitNacos("edu", "user-api", "config.yaml")
	//boot.InitNacos("edu", "user", "etcd.yaml.bak") //不能重复加载，否则被覆盖
	ctx := gctx.GetInitCtx()

	// 检查是否可用
	//g.Dump(g.Cfg().Available(ctx))

	// 输出所有配置
	//g.Dump(g.Cfg().Data(ctx))
	address, err := g.Cfg().Get(ctx, "etcd.address")
	if err != nil {
		panic(err)
	}
	//fmt.Println(etcd)
	grpcx.Resolver.Register(etcd.New(address.String()))
	//初始化rpcClient
	logic.RpcCli = logic.NewRpcClient()
	cmd.Main.Run(ctx)

	/*var ctx = gctx.New()
	conf, err := g.Cfg("etcd").Get(ctx, "etcd.address")
	if err != nil {
		panic(err)
	}

	var address = conf.String()
	grpcx.Resolver.Register(etcd.New(address))
	//初始化rpcClient
	logic.RpcCli = logic.NewRpcClient()
	cmd.Main.Run(ctx)*/
}
